<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="favicon.ico"> <link href="/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.min.css" rel="stylesheet">
     <meta http-equiv="Cache-control" content="no-cache">
	<meta http-equiv="Cache" content="no-cache">
    <link href="/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">
    <link href="/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <style type="text/css">
     .layui-layer-setwin.layui-layer-close2{
          right: -10px !important;
          top: -10px !important;
      }
      html,body{
		-moz-user-select: none;
		-khtml-user-select: none;
		user-select: none;
	  }
      .checkbox{
	  	display: inline-block;
	  	width: 30%;
	  	min-height: 39px !important;
	  }
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-6">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="signupForm">
                        	<div class="form-group">
                             <label class="col-sm-3 control-label">父功能：</label>
                             <div class="col-sm-8">
                                  <input type="hidden" name="parentid" id="parentid">
                                  <input name="parentName" id="parentName"   class="form-control"  type="text" readonly="readonly">
                             </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">功能代码：</label>
                                <div class="col-sm-8">
                                    <input id="funid" name="funid" class="form-control" type="text" aria-required="true" aria-invalid="true" readonly="readonly" class="error">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">功能名称：</label>
                                <div class="col-sm-8">
                                    <input id="fundesc" name="fundesc" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                </div>
                            </div>
                            <div class="checkbox checkbox-info">
                                        <input id="botfalgCheckbox" value="1" name="botflag" type="checkbox"><label for="botfalgCheckbox">菜单项</label>
                             </div>
                             <div class="checkbox checkbox-info">
                                        <input id="useflagCheckbox" value="1" name="useflag" type="checkbox"><label for="useflagCheckbox">可用</label>
                             </div>
                             <div class="checkbox checkbox-info">
                                        <input id="displayfunCheckbox" value="1" name="displayfun" type="checkbox"><label for="displayfunCheckbox">展示权限</label>
                             </div>
                            <!--  <div class="form-group">
                             <label class="col-sm-3 control-label">是否可用：</label>
                             <div class="col-sm-8">
                               <label class="control-label">
                                 <input type="radio" value="0" id="optionsRadios11" checked="checked" name="useflag">否
                                 <input type="radio" value="1" id="optionsRadios22" name="useflag">是
                              </label>
                             </div>
                            </div> 
                             <div class="form-group">
                             <label class="col-sm-3 control-label">是否菜单：</label>
                             <div class="col-sm-8">
                               <label class="control-label">
                                 <input type="radio" value="0" id="optionsRadios1"  name="botflag">否
                                 <input type="radio" value="1" id="optionsRadios2" name="botflag">是
                              </label>
                             </div>
                            </div>
                            
                            <div class="form-group" id="showTrPower">
                             <label class="col-sm-3 control-label">是否展示权限：</label>
                             <div class="col-sm-8">
                               <label class="control-label">
                                 <input type="radio" value="0" id="optionsRadios1" checked="checked" name="displayfun">否
                                 <input type="radio" value="1" id="optionsRadios2" name="displayfun">是
                              </label>
                             </div>
                            </div> -->
                           <div class="form-group showTrMenu" style="display:none">
                             <label class="col-sm-3 control-label">菜单路径：</label>
                             <div class="col-sm-8">
                                  <input id="funpath" name="funpath" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                             </div>
                            </div>
                             <div class="form-group showTrMenuImage" style="display:none">
	                             <label class="col-sm-3 control-label">原始菜单图标：</label>
	                             <div class="col-sm-8">
	                                    <img id="dyFileImage" style="width:60px"></img>
	                             </div>
                             </div>
                             <div class="form-group showTrMenu" style="display:none">
                             <label class="col-sm-3 control-label">菜单图标：</label>
                             <div class="col-sm-8">
                                 <div id="dyFile">
                                        <input type="hidden" name="attachid" id="attachid"/>
                                        <input type="file" id="attachFile" name="attachFile" accept="image/*" class="form-control">
                                 </div>
                              </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">排序值：</label>
                                <div class="col-sm-8">
                                    <input id="orderval" name="orderval" class="form-control" type="text">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-8">
                                    <button class="btn btn-primary" type="submit">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="/js/jquery.min.js?v=2.1.4"></script>
    <script src="/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="/js/content.min.js?v=1.0.0"></script>
    <script src="/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="/js/plugins/validate/messages_zh.min.js"></script>
    <script src="/js/plugins/layer-pc/layer.js"></script>
    <script src="/common/form-validator.js"></script>
    <script src="/common/petecat.js"></script>
    <script src="/js/jquery.cookie.js"></script>
    <script src="/js/plugins/sweetalert/sweetalert.min.js"></script>
	<script type="text/javascript">
	checkPowerAndJump("MODSYSFUN");
	 function setInitData(row){
	    	changeElement($("input[name='botflag']:checked").val());
	    	$("#parentName").val(row.parentName);
	    	if($.trim(row.attachid)!=''){//加载图片
	    		loadFileUrl(row);
	    	}
	    }
		$(function(){
			$("#attachFile").change(function(){
				var file = this.files[0];
				if(!checkFileType("attachFile")){
					sweetAlert("文件类型错误", "请上传png，jpg图片!", "error");
					$(this).val('');
		            return;
		        }
			})
			$("#parentName").click(function(){
				parent.layer.open({
	    			type: 2,
	    		    title: false,
	    		    shade: 0.2,
	    		    skin: 'layui-layer-self',
	    		    area: ['100%', '100%'],
	    		    content: ['/user/sysfun/chooseParent.html', 'auto'], //iframe的url，no代表不显示滚动条
	    		    success:function(layero, index){
	    		    	
	    		    	
	    		    }
	    		});
			})
			$("input[name='botflag']").click(function(){
				$("#showTrPower").toggle();
				$(".showTrMenu").toggle();
			})
			var e = "<i class='fa fa-times-circle'></i> ";
		    $("#signupForm").validate({
		        rules: {
		        	funid: {
		                required: true,
		                maxlength: 30,
		                isWord:true
		            },
		            fundesc: {
		                required: true,
		                maxlength: 100
		            },
		            funpath: {
		                required: false,
		                maxlength: 100
		            },
		            orderval: {
		                required: true,
		                min:1,
		                max:1000
		            }
		        },
		        messages: {
		        	funid: {
		                required: e + "请输入功能代码",
		                maxlength: e + "功能代码不能超过30个字符"
		            },
		            fundesc: {
		                required: e + "请输入功能名称",
		                maxlength: e + "功能名称不能超过100个字符"
		            },
		            funpath:{
		            	maxlength: e + "菜单路径不能超过100个字符"
		            }
		        },
		        submitHandler:function(form){
		        	//先上传文件
		        	var value = $("#attachFile").val();
		        	if($.trim(value)!=''){
		        		var result = sendSingleFile("attachFile",{dataParams:{system:'1',type:'1'}});
		        		if(result.code !=SUCCESS_CODE){
		        			sweetAlert("上传文件错误", result.message, "error");
		        			return false;
		        		}else{
		        			$("#attachid").val(result.data);
		        		}
		        	}
		        	var data = serializeForm(form);
		        	var formData = JSON.stringify(data);
		        	var req = {};
		        	req['reqJSON'] = {
	        			type : 'put',
	        			url : SSO_URL+'/sy/sysfun/updateFun',
	        			data : formData
		        	};
		        	req['useToken'] = true;
		        	req['successFn'] = function(respData){
		        		layer.msg(respData.message, {icon: 6},function(){
        					if(respData.code == SUCCESS_CODE){
    						 	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
   	                        	parent.layer.close(index);  
        					}
        				}); 
		        	};
		        	ajaxRequest(req);
		        }
		    })
		});
		function changeElement(bootflag){
			if(bootflag=='1'){
				$("#showTrPower").css("display","none");
				$(".showTrMenu").css("display","");
			}else{
				$("#showTrPower").css("display","");
				$(".showTrMenu").css("display","none");
			}
		}
		function setParentFun(funid,fundesc){
			$("#parentid").val(funid);
			$("#parentName").val(fundesc);
		}

		function loadFileUrl(row){
			var thatRow = row;
			var attachUrl = null;
			var req = {};
			req['reqJSON'] = {
					type : 'get',
					url : FILE_URL+'/getById',
					data:{id:row.attachid}
				};
				req['useToken'] = true;
				req['successFn'] = function(respData){
					if(respData.code==SUCCESS_CODE){
						if(respData.data !=null && respData.data.length>0){
							var attachUrl = respData.data[0];
							if(attachUrl!=null){
								var defalutUrl=FILE_VIEW_URL+attachUrl;
			                    $('#dyFileImage').attr("src",defalutUrl);
			                    $(".showTrMenuImage").css("display","")
							}
							
						}
					}
				};
				ajaxRequest(req);
				
		}
	</script>
</body>
</html>